﻿Public Class Document

    Private _DocumentInfo As IO.FileInfo

    Sub New(ByVal FullPath As String)
        _DocumentInfo = New IO.FileInfo(FullPath)

        If _DocumentInfo.Exists = False Then
            Dim m As MsgBoxResult = MsgBox("It would seem that the INI selected does not exist." & vbNewLine & "Create it now?", MsgBoxStyle.YesNo)

            If m = MsgBoxResult.Yes Then
                My.Computer.FileSystem.WriteAllText(_DocumentInfo.FullName, "", False)
            End If
        End If
    End Sub

    Public ReadOnly Property IsProperINI() As Boolean
        Get
            If _DocumentInfo.Extension.EndsWith("ini") Then Return True
            Return False
        End Get
    End Property

    Public ReadOnly Property INILines() As String()
        Get
            Dim Text As String = My.Computer.FileSystem.ReadAllText(_DocumentInfo.FullName)
            Text = Text.Replace(vbCr, vbNewLine)
            Text = Text.Replace(vbCrLf, vbNewLine)
            Dim splitLines() As String = Text.Split(vbNewLine)
            Dim Lines As New List(Of String)



            For i As Integer = 0 To splitLines.Length - 1
                Dim CurrentLine As String = splitLines(i)

                Lines.Add(CurrentLine.Trim())
            Next
            Return Lines.ToArray()
        End Get
    End Property

    Public ReadOnly Property FirstLineIndex() As Integer
        Get
            Return 0
        End Get
    End Property

    Public ReadOnly Property LastLineIndex() As Integer
        Get
            Return INILines.Count - 1
        End Get
    End Property

    Public ReadOnly Property FileInfo() As IO.FileInfo
        Get
            Return _DocumentInfo
        End Get
    End Property



End Class
